package com.example.mymessagequeue.test;

import com.example.mymessagequeue.mqclient.Channel;
import com.example.mymessagequeue.mqclient.Connection;
import com.example.mymessagequeue.mqclient.ConnectionFactory;
import com.example.mymessagequeue.mqserver.core.BasicProperties;
import com.example.mymessagequeue.mqserver.core.ExchangeType;

import java.io.IOException;

public class Product {
    public static void main(String[] args) throws IOException, InterruptedException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(7772);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("test.exchange", ExchangeType.DIRECT, true, false, null);
        channel.queueDeclare("test.queue", true, false, false, null);
//        channel.queueBind("testQueue", "testExchange", "");

        int i = 0;
        while (true) {
//            if (i % 10 == 0) {
//                Thread.sleep(5000);
//            }
            BasicProperties basicProperties = new BasicProperties();
            basicProperties.setDeliverMode(2);
            channel.basicPublish("test.exchange", "test.queue", basicProperties, ("hello" + i).getBytes());
            i++;
        }

    }
}
